#!/bin/bash
function subem {

#pwd
if [ -a extend.sh ]; then
   node=`head -1 extend.sh | awk -F ":" '{print $2}'`
else
   node=`head -1 em.sh | awk -F ":" '{print $2}'`
fi
njobs=`/opt/torque/bin/qstat -an1 | egrep $node | wc -l`
queue=`/opt/torque/bin/qstat -an1 | egrep $j | wc -l`
if [ -a md/md.nohup ]; then
thanx=`tail -10 md/md.nohup | egrep gcq | awk '{print $2}'`
else
thanx=""
fi

#echo "node=$node njobs=$njobs queue=$queue thanx=$thanx"

if [ "$thanx" = "Thanx" ]; then
      echo "$j: finished"
else
  if [ $queue = "0" ]; then
    if [ "$njobs" = "0" ]; then
      echo "$j: submitted (node $node)"
      $PWD/g_submit
    else
      echo "$j: waiting ($node busy)"
    fi
  else
    echo "$j: running"
  fi
fi
}

#for j in md108
#do
#cd /home/bentenin/gromacs/mshmoh/skb/$j
#subem $j
#done

cd /home/bentenin/gromacs/mshmoh/siepmann/md087
j=md087
subem md087
cd /home/bentenin/gromacs/msmmoh/x0875/md068
j=md068
subem md068
cd /home/bentenin/gromacs/msmmoh/x0750/md063
j=md063
subem md063
cd /home/bentenin/gromacs/msmmoh/x0625/md065
j=md065
subem md065
cd /home/bentenin/gromacs/msmmoh/x0500/md067
j=md067
subem md067
cd /home/bentenin/gromacs/msmmoh/x0375/md066
j=md066
subem md066
cd /home/bentenin/gromacs/msmmoh/x0250/md064
j=md064
subem md064
cd /home/bentenin/gromacs/msmmoh/x0125/md062
j=md062
subem md062

